Shiny.addCustomMessageHandler("barchart_values", function(message) {
    var dataset = message.n;

    //Width and height
    var w = 512;
    var h = 50;

    var sortOrder = false;

    var xScale = d3.scaleBand()
	.domain(d3.range(dataset.length))
	.range([0, w])
	.paddingInner(0.5);

    var yScale = d3.scaleLinear()
	.domain([0, d3.max(dataset)])
	.range([0, h]);

    //Create SVG element
    var barchart = d3.select("#barchart_area")
	.append("svg")
	.attr("width", w)
	.attr("height", h);

    //Create bars
    barchart.selectAll("rect")
	.data(dataset)
	.enter()
	.append("rect")
	.attr("x", function(d, i) {
	    return xScale(i);
	})
	.attr("y", function(d) {
	    return h - yScale(d);
	})
	.attr("width", xScale.bandwidth())
	.attr("height", function(d) {
	    return yScale(d);
	})
	.attr("fill", function(d) {
	    return "rgb(0, 0, " + Math.round(d * 10) + ")";
	});
});
